home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / MISCEOUS / YRCAL17T.LZH / YRCLAGG.C < prev    next >
Text File  |  1989-10-02  |  5KB  |  185 lines

  1. /********************************************************************
  2. **  YRCLAGG.C v0.17T  Copyright (c) 1987, 1988, 1989 by Paul M. Sittler.
  3. **
  4. **  Produces an "AGGIE" calendar for YEARCAL.
  5. **
  6. **  All rights reserved.  The copyright owner hereby authorizes the
  7. **  no-charge, noncommercial making and/or distribution of copies of
  8. **  the entirety of this work unchanged and unincorporated in any
  9. **  other work (except "LiBRary" or "ARChive" disk files for the sole
  10. **  purpose of no-charge noncommercial distribution).  No other
  11. **  reproduction or use is authorized without the express prior
  12. **  written consent of the copyright owner.
  13. **
  14. **************************************************************/
  15.  
  16. /* ANSI header files included:  */
  17. #include <stdio.h>    /* fclose, fopen, fp, fprintf, fputs, */
  18.             /* gets, printf, rename, sprintf, stderr */
  19. #include <stdlib.h>    /* exit */
  20. #include <string.h>    /* strcat, strcmp, strcpy, strlen */
  21.  
  22. #include "yearcal.def"
  23.  
  24. /* External variables and structures declared in YEARCAL.C */
  25. extern char *lingo[];            /* Names of languages array */
  26. extern char *mnam[][12];        /* Names of months array */
  27. extern char *wkday[][7];        /* Names of days array */
  28. extern int yr[][12][6][7];        /* Array for 3 yrs, 4-D, */
  29.                     /* 3 years,      12 months/year, */
  30.                     /* 6 weeks/month, 7 days/week */
  31. extern char *new_file;
  32. extern char *file;
  33. extern FILE *fp;
  34.  
  35.  
  36.  
  37. void agg_printer(int year, char out, char base, int lang, char pause)
  38. /* char base;    Number base used, 0 = Decimal, H = Hex, O = Octal */
  39. /* int lang;    Language used 1 = Danish, 2 = Dutch, 3 = English etc. */
  40. /* char pause;    Page pause True/False */
  41. {
  42.     int mf[12][2];    /* mf flag for aggie calendar */
  43.  
  44.     char agg1[] = {" Ja Fe Mr Ap My Jn Jl Au Se Oc No De"},
  45.      agg2[] = {" -- -- -- -- -- -- -- -- -- -- -- --"};
  46.  
  47.     int y,
  48.     month,
  49.     week,
  50.     day,
  51.     count,
  52.     stat,
  53.     i,
  54.     j;
  55.  
  56.     char  linbuf[BUF],
  57.       temp[BUF];
  58.  
  59.     char *off = (out == 'V') ?
  60.              " " :
  61.               "    " ;
  62.     y = 1;                /* Make year this year */
  63.     sprintf(agg1, " %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s %2.2s",
  64.        mnam[lang - 1][0], mnam[lang - 1][ 1], mnam[lang - 1][ 2],
  65.        mnam[lang - 1][3], mnam[lang - 1][ 4], mnam[lang - 1][ 5],
  66.        mnam[lang - 1][6], mnam[lang - 1][ 7], mnam[lang - 1][ 8],
  67.        mnam[lang - 1][9], mnam[lang - 1][10], mnam[lang - 1][11] );
  68.  
  69.     if (out == 'F')
  70.     {
  71.     sprintf(file, "%dAGG%c", year, base);
  72.     strcpy(new_file, file);
  73.     strcat(file, ".$$$");
  74.     sprintf(temp, ".%3.3s", lingo[lang - 1]);
  75.     strcat(new_file, temp);
  76.     fp = fopen(file, "w");
  77.     }
  78.  
  79.     if (pause     &&            /* User wants time after each page */
  80.     out == 'P' )            /* gets printed to add paper etc... */
  81.     hold();                /* Wait for keystroke */
  82.  
  83.     fputs("\n\n\n", fp);
  84.     sprintf(temp, "%sAggie %s%sGig'Em %s Calander fer %d",
  85.          (base == 'O') ? "Olde " : "" ,
  86.          base ? "Hacker's " : "" ,
  87.          base ? ( (base == 'O') ? "Octal " : "Hexadecimal ") : "",
  88.          lingo[lang - 1],
  89.          year);
  90.     fputs(center(temp, out == 'V' ? 75 : 89), fp);
  91.     fputs("\n\n\n", fp);
  92.  
  93.     for (day = 0;
  94.      day < 7;            /* 4 sets of days */
  95.      day += 2)            /* 2 days across */
  96.     {
  97.      for (i = 0;
  98.           i < 12;            /* 12 months in a day */
  99.           i++)
  100.          for (j = 0;
  101.           j < 2;        /* 2 days across */
  102.           j++)
  103.          mf[i][j] = 0;
  104.  
  105.     if (day < 6)
  106.     {
  107.         sprintf(linbuf, "%s%s    ", off, center(wkday[lang - 1][day], 36));
  108.         sprintf(temp,   "%s\n"  , center(wkday[lang - 1][day + 1], 36));
  109.         strcat(linbuf, temp);
  110.         fputs(linbuf, fp);
  111.         linbuf[0] = '\0';
  112.         fprintf(fp, "%s%s   %s\n", off, agg1, agg1);
  113.         fprintf(fp, "%s%s   %s\n", off, agg2, agg2);
  114.     }
  115.     else                 /* day = 6 */
  116.     {
  117.         fprintf(fp, "%s%s\n", off, trim(center(wkday[lang - 1][day], 79) ) );
  118.         fprintf(fp, "%s%s\n", off, trim(center(agg1, 79) ) );
  119.         fprintf(fp, "%s%s\n", off, trim(center(agg2, 79) ) );
  120.     }
  121.  
  122.     for (week = 0;
  123.          week < 5;            /* 5 weeks/day possible */
  124.          week++)
  125.     {
  126.         sprintf(linbuf, off);
  127.  
  128.         for (count = 0;        /* 2 days across except Saturday */
  129.          count < ( (day == 6) ?
  130.                     1 :
  131.                     2  );
  132.          count++)
  133.         {
  134.         if (day == 6)        /* Saturday */
  135.             strcat(linbuf, "                     ");
  136.  
  137.         for (month = 0;
  138.              month < 12;    /* 12 months/day */
  139.              month++)
  140.         {
  141.             if (!yr[y][month][week][day + count])
  142.             mf[month][count] = 1;
  143.  
  144.             sprintf(temp,
  145.              yr[y][month][week + mf[month][count]][day + count] ?
  146.                 (base ?
  147.                 ((base == 'O') ? "%3o" : "%3X" ) :
  148.                          "%3d" ) :
  149.                          "   ",
  150.              yr[y][month][week + mf[month][count]][day + count]);
  151.             strcat(linbuf, temp);
  152.         }
  153.  
  154.         strcat(linbuf, count < 1 ?
  155.                    "   " :
  156.                    "\n"    );
  157.  
  158.         if (day == 6)        /* Saturday */
  159.             strcat(linbuf, "\n");
  160.         }
  161.  
  162.         fputs(linbuf, fp);
  163.         linbuf[0] = '\0';
  164.     }
  165.     fputs("\n\n", fp);
  166.     }
  167.  
  168.     if (out != 'V')
  169.     fputs("\f\r", fp);        /* no FF for screen */
  170.  
  171.     if (out == 'F')            /* Setup for file output */
  172.     if ((stat = fclose(fp)) == ERROR)
  173.         printf("\nCan't close %s.\n", file);
  174.  
  175.     if (out == 'F')
  176.     if ((stat = rename(file, new_file)) == ERROR)
  177.         printf(
  178.         "\nCan't rename %s to %s.  %s may already exist.\n",
  179.                 file, new_file,
  180.                        new_file);
  181. }
  182.  
  183.  
  184.  
  185.